package com.flyduck.vueshop.system.remote.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.vueshop.common.core.utils.BeanUtils;
import com.flyduck.vueshop.system.remote.service.RemoteUserService;
import com.flyduck.vueshop.system.vo.RemoteUserRespVO;
import com.flyduck.vueshop.system.entity.SysUser;
import com.flyduck.vueshop.system.mapper.SysUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * SysUserApiServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-09
 */
@Service
public class RemoteUserServiceImpl implements RemoteUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public RemoteUserRespVO getUserByUsername(String username) {
        SysUser sysUser = sysUserMapper.selectOne(
                new LambdaQueryWrapper<SysUser>()
                        .eq(SysUser::getUsername, username)
        );
        RemoteUserRespVO remoteUserRespVO = BeanUtils.toBean(sysUser, RemoteUserRespVO.class);
        return remoteUserRespVO;
    }

    @Override
    public RemoteUserRespVO getUserById(Long id) {
        SysUser sysUser = sysUserMapper.selectById(id);
        RemoteUserRespVO remoteUserRespVO = BeanUtils.toBean(sysUser, RemoteUserRespVO.class);
        return remoteUserRespVO;
    }
}
